import fs from 'fs'
// 读取文件方法
function readFile(path: string) {
  return new Promise((resolve, reject) => {
    fs.readFile(
      path,
      { flag: 'r', encoding: 'utf-8' },
      (err: NodeJS.ErrnoException | null, data: string) => {
        if (err) {
          reject('出错啦')
        }
        resolve(data)
      }
    )
  })
}

function writeFile(path: string, data: string) {
  return new Promise((resolve, reject) => {
    fs.writeFile(path, data, (err: NodeJS.ErrnoException | null) => {
      if (err) {
        reject('出错啦')
      }
      resolve(null)
    })
  })
}
export { readFile, writeFile }
